<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib prefix="c"  uri="http://java.sun.com/jsp/jstl/core" %>
<%@taglib prefix="shiro" uri="http://shiro.apache.org/tags" %>
<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
  <title>${SYSTEM_NAME}</title>
	<link rel="stylesheet" href="${pageContext.request.contextPath}/static/layuiadmin/layui/css/layui.css" media="all">
	<link rel="stylesheet" href="${pageContext.request.contextPath}/static/layuiadmin/style/admin.css" media="all">
</head>
<body >
<div class="layui-fluid" style="background-color: #fff;">
		<form class="layui-form" action="" style="width:100%" method="post" name="publishUser-form">
		  <div class="layui-form-item">
		    <label class="layui-form-label layui-form-required">旧密码</label>
		    <div class="layui-input-inline">
		      <input type="password" name="oldPassword" lay-verify="require" placeholder="请输入密码" class="layui-input" autocomplete="off">
		    </div>
		    <div class="layui-form-mid layui-word-aux">请填写旧密码</div>
		  </div>
			
		  <div class="layui-form-item">
		    <label class="layui-form-label layui-form-required">新密码</label>
		    <div class="layui-input-inline">
		      <input id="pwd" type="password" name="password" lay-verify="pass" placeholder="请输入密码" class="layui-input" autocomplete="off">
		    </div>
			  <c:if test="${pwdStrength == 0}">
				  <div class="layui-form-mid layui-word-aux">请填写6到12位密码</div>
			  </c:if>
			  <c:if test="${pwdStrength == 1}">
				  <div class="layui-form-mid layui-word-aux">包含6-16个字符，至少1个字母和1个数字</div>
			  </c:if>
			  <c:if test="${pwdStrength == 2}">
				  <div class="layui-form-mid layui-word-aux">包含6-16个字符，至少1个大写字母，1个小写字母和1个数字</div>
			  </c:if>
		  </div>
		  <div class="layui-form-item">
		    <label class="layui-form-label layui-form-required">验证密码</label>
		    <div class="layui-input-inline">
		      <input type="password" name="repassword" lay-verify="rePassword" placeholder="请输入密码" class="layui-input">
		    </div>
		    <div class="layui-form-mid layui-word-aux">验证密码必须和密码一致</div>
		  </div>
		  
		  <div class="layui-form-item">
		    <div class="layui-input-block">
		      <button class="layui-btn" lay-submit="" lay-filter="sub">立即提交</button>
<%--		      <button type="reset" class="layui-btn layui-btn-primary">重置</button>--%>
		      <button type="button" class="layui-btn layui-btn-normal" onclick="closed()">关闭</button>
		    </div>
		  </div>
		</form>
  	  </div>
<script src="${pageContext.request.contextPath}/static/js/common-2.0.0.js?v=${FILE_VERSION}"></script>
<script src="${pageContext.request.contextPath}/static/layuiadmin/layui/layui.js?v=${FILE_VERSION}"></script>
<script src="${pageContext.request.contextPath}/static/js/jquery-3.3.1.min.js?v=${FILE_VERSION}"></script>
<script>
//JavaScript代码区域
layui.use(['form','element'], function(){
	var form = layui.form;
	var element = layui.element;

	var pwdStrength = ${pwdStrength};
	
	form.verify({
		pass: function(value, item) {
		var pattern;
		if(pwdStrength == 0){
			pattern = /^[\S]{6,12}$/;
			if(!pattern.test(value)){
				return '密码必须6到12位，且不能出现空格';
			}
		}else if(pwdStrength == 1){
			//至少8-16个字符，至少1个字母和1个数字，其他可以是任意字符：
			pattern = /^(?=.*?[a-z)(?=.*>[A-Z])(?=.*?[0-9])[a-zA_Z0-9]{6,16}$/;
			if(!pattern.test(value) ){
				return '密码应包含6-16个字符，至少1个字母和1个数字';
			}
		}else{
			//至少8-16个字符，至少1个大写字母，1个小写字母和1个数字，其他可以是任意字符：
			pattern = /^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)[^]{6,16}$/;
			// pattern = /^(?=.*[0-9])(?=.*[a-z])(?=.*[A-Z])([a-zA-Z0-9]{6,16})$/;
			if(!pattern.test(value) ){
				return '密码应包含6-16个字符，至少1个大写字母，1个小写字母和1个数字';
			}
		}
	}
	  ,rePassword : function(value, item){
		  //alert(value);
		  //alert(document.getElementById("pwd"));
		  var passValue = $("#pwd").val();
		  
		  if(passValue != value){
	      	return '两次密码输入不一致';
	      }
	  }
	});
	
	form.on('submit(sub)', function(data){
		$ajax({
			url: "/sys/main/editPwd/save",
			data: data.field,
	        succCallback: function (json) {
	        	if(json.code == 0){
            		var index = parent.layer.getFrameIndex(window.name); //获取窗口索引  
            		parent.layer.close(index);//关闭弹出的子页面窗口
            		parent.layer.msg(json.msg);
            	}
	        }
		});
		return false; //阻止表单跳转。如果需要表单跳转，去掉这段即可。
	});
});

function closed(){
	var index = parent.layer.getFrameIndex(window.name); //获取窗口索引  
	parent.layer.close(index);//关闭弹出的子页面窗口
}
</script>
</body>
</html>